<?php
class Cellphonezone_Digg_Block_Digg extends Mage_Core_Block_Template{

/**
     * Retrieve current product model
     *
     * @return Mage_Catalog_Model_Product
     */
    public function getProduct()
    {
        return Mage::registry('product');
    }  
    public function saveDigg(){
        $diggProduct = $this->getDiggProduct();
        $remoteAddr = Mage::getSingleton('log/visitor')->getRemoteAddr();
        $productId = $this->getProduct()->getId();
        $diggProduct->setId($productId)->setRemoteAddr($remoteAddr)->setCustomerId(Mage::getSingleton('customer/session')->getCustomer()->getId())->setVisitorId(Mage::getSingleton('log/visitor')->getId())->setCreationTime(date('Y-m-d H:i:s'))->save();
        return $diggProduct; 
    } 
    public function getDiggProduct(){

        if( ! $this->getData('digg_product') instanceof Cellphonezone_Digg_Model_Digg_Product){
            $remoteAddr = Mage::getSingleton('log/visitor')->getRemoteAddr();
            $productId = $this->getProduct()->getId();
            $diggProduct = Mage::getModel('digg/digg_product')->loadByProductAndIP($productId,$remoteAddr);
            $this->setDiggProduct($diggProduct);
        }
        return $this->getData('digg_product'); 
    }
    public function getDigg(){
        if( ! $this->getData('digg') instanceof Cellphonezone_Digg_Model_Digg){
            $productId = $this->getProduct()->getId();
            $digg = Mage::getModel('digg/digg')->load($productId,'product_id');
            $this->setDigg($digg);
        }
        return $this->getData('digg'); 
    
    }

}
